package com.six.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.six.exception.CustomerException;
import com.six.mapper.BuyPlanMapper;
import com.six.pojo.BuyPlan;
import com.six.result.MessageCode;
import com.six.service.BuyPlanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class BuyPlanServiceImpl extends ServiceImpl<BuyPlanMapper, BuyPlan> implements BuyPlanService {
    @Override
    public void add(BuyPlan buyPlan) {
        //添加数据之前要判断本月是否已经添加过了
        BuyPlan planByReq = getBaseMapper().findPlanByReq(buyPlan.getDate(), buyPlan.getMaterialId());

        if (planByReq!=null){
            log.info("本月已经添加过该物料计划了");
            //TODO 修改提示信息
            throw new CustomerException(MessageCode.USERNAME_EXIST);
        }
        //添加
        getBaseMapper().insert(buyPlan);
    }




}
